<?php

namespace AppBundle\Controller;

use AdminBundle\Entity\HuobiCalcKline10min;
use AdminBundle\Entity\HuobiMarketKline10min;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Symfony\Component\HttpFoundation\Request;

class HuobiKLine10minController extends HuobiKlineBaseController
{
    const CACHE_KLINE_KEY = 'list:kline_10min';

    /**
     * 接收WEBSOCKET同步过来的火币K线图（10分钟）数据
     * @Route("/kline10min", name="huobi_market_kline_10min")
     */
    public function indexAction(Request $request)
    {
        return parent::receiveKline($request);
    }

    protected function KlineInstance($data_now, $prefix)
    {
        $huobiMarketKline10min = new HuobiMarketKline10min($data_now, $prefix);
        return $huobiMarketKline10min;
    }

    protected function getKline($coin, $timestamp = 0, $duration = 60)
    {
        $em = $this->getDoctrine()->getManager();
        $data = $em->getRepository('AdminBundle:HuobiMarketKline10min')->get60mins($coin, $timestamp, $duration);
        return $data;
    }

    protected function klinePeriod()
    {
        $kline_multiple = [
            "3" => 3, "5" => 5, "7" => 7, "10" => 10, "15" => 15, "20" => 20, "30" => 30,
            "60" => 60, "120" => 120, "180" => 180, "240" => 240];

        return $kline_multiple;
    }

    protected function KlineCalcInstance($data)
    {
        $huobiCalcKline10min = new HuobiCalcKline10min($data);
        return $huobiCalcKline10min;

    }

    protected function cacheKey()
    {
        return self::CACHE_KLINE_KEY;
    }

    protected function calcKlineMinSize()
    {
        $min_size = parent::calcKlineMinSize() - 1;
        return $min_size;
    }

}
